package me.zhengjie.minbearwcs.dao.rework.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.rework.inf.ReworkTaskRecordDao;
import me.zhengjie.minbearwcs.entity.Mapper.rework.ReworkTaskRecordMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.rework.ReworkTaskRecord;
import me.zhengjie.minbearwcs.entity.PO.wcs.rework.status.ReworkTaskRecordStatus;
import org.apache.xmlbeans.impl.regex.REUtil;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
@RequiredArgsConstructor
public class ReworkTaskRecordDaoImpl implements ReworkTaskRecordDao {

    private final ReworkTaskRecordMapper mapper;

    @Override
    public boolean insert(ReworkTaskRecord reworkTaskRecord) {
        return mapper.insert(reworkTaskRecord) == 1;
    }

    @Override
    public ReworkTaskRecord selectByRecordId(String detailId) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(ReworkTaskRecord::getReworkTaskRecordId, detailId)
                .oneOpt()
                .orElse(null);
    }

    @Override
    public boolean updateStartTimeByRecordId(String recordId, LocalDateTime localDateTime) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(ReworkTaskRecord::getReworkTaskRecordId,recordId)
                .set(ReworkTaskRecord::getStartTime,localDateTime)
                .update();
    }

    @Override
    public boolean updateStatusByRecordId(String recordId, ReworkTaskRecordStatus status) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(ReworkTaskRecord::getReworkTaskRecordId,recordId)
                .set(ReworkTaskRecord::getStatus,status)
                .update();
    }

    @Override
    public boolean updateEndPointByRecordId(String recordId, String endPoint) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(ReworkTaskRecord::getReworkTaskRecordId,recordId)
                .set(ReworkTaskRecord::getEndPoint,endPoint)
                .update();
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) == 1;
    }
}
